import matplotlib.pyplot as plt
import numpy as np

# 现金流量数据
cash_flow_data = {
    'Net Cash Flow from Operating Activities': [12966244.05, -168524231.02],
    'Net Cash Flow from Investing Activities': [311677337.13, -69447171.23],
    'Net Cash Flow from Financing Activities': [-357648490.89, 196359492.80]
}

# 准备数据
items = list(cash_flow_data.keys())
first_half_2024 = [data[0] for data in cash_flow_data.values()]
annual_2023 = [data[1] for data in cash_flow_data.values()]

x = np.arange(len(items))  # the label locations
width = 0.35  # the width of the bars

# 绘制柱状图
fig, ax = plt.subplots(figsize=(10, 6))
rects1 = ax.bar(x - width/2, first_half_2024, width, label='First Half 2024')
rects2 = ax.bar(x + width/2, annual_2023, width, label='Annual 2023')

# 添加文本标签、标题和自定义x轴刻度标签
ax.set_ylabel('Amount (CNY)')
ax.set_title('Cash Flow Comparison between First Half 2024 and Annual 2023')
ax.set_xticks(x)
ax.set_xticklabels(items)
ax.legend()

# 在柱状图上添加数值标签
def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        ax.annotate('{}'.format(height),
                    xy=(rect.get_x() + rect.get_width() / 2, height),
                    xytext=(0, 3),  # 3 points vertical offset
                    textcoords="offset points",
                    ha='center', va='bottom')

autolabel(rects1)
autolabel(rects2)

# 显示图形
plt.show()